package com.woniu.day8.controller;


import com.woniu.day8.pojo.dto.UserInfoDto;
import com.woniu.day8.service.ALiYunOssSevice;
import com.woniu.day8.util.ResultMessage;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


import java.io.IOException;

@RestController
@RequestMapping("oss")
@CrossOrigin
public class ALiYunOssController {

    @Autowired
    private ALiYunOssSevice aLiYunOssSevice;

    /**
     * 更新头像
     */
    @PostMapping("updateAvatar")
    public ResultMessage updateAvatar(MultipartFile file, HttpSession session, UserInfoDto uDto) throws IOException {
        //获取当前用户名称
        String username = uDto.getUsername();
        //调用service层获取oss返回访问图片链接
        String url = aLiYunOssSevice.updateAvatar(file,username);
        return ResultMessage.success(url);
    }
}